# Author: HZT
# Date: 2023/10/23
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import page
from config.config_loader import config
from page.web_ck_pm import WebCkPm
from page.web_ck_qz import WebCkQz
from utils import UtilsDriver, login_with_session, GetLog, generate_random_string, generate_random_string_sz


class TestWebCkQz:

    def setup_class(self):
        self.log = GetLog.get_log()
        self.driver = UtilsDriver.get_web_driver()
        # 实例化
        self.ckQz = WebCkQz(self.driver)
        self.ckpm = WebCkPm(self.driver)
        self.mc = "穿越火线" + generate_random_string_sz(3)
        # 打开网页
        self.driver.get(config.URL)
        login_with_session('system1', self.driver)

    def teardown_class(self):
        # 在所有测试用例执行完毕后，关闭浏览器
        # UtilsDriver.get_web_driver().quit()
        pass

    # 新增群组成功
    def test01_ck_qz(self):
        try:
            self.ckQz.ck_qz_click_qzgl()
            self.ckQz.ck_qz_click_kscj()
            self.ckQz.ck_qz_input_mc(self.mc)
            self.ckQz.ck_qz_click_tj()
            assert "保存成功" in self.ckQz.ck_qz_get_bccg()
        except Exception as e:
            self.log.error(f"新增群组异常，原因是{e}")
            self.ckQz.base_get_img()
            assert False

    # 人员管理新增人员绑定群组成功
    def test02_ck_qz(self):
        try:
            timestamp = str(int(time.time()))
            username = 'test' + timestamp
            self.ckpm.ck_pm_click_rygl()
            self.ckpm.ck_pm_click_xz()
            self.ckpm.ck_pm_xz(username, username, pwd="qwe123", fz=self.mc)
            self.ckpm.ck_pm_get_xz()
            assert self.mc == self.ckpm.ck_pm_get_fzlb()
        except Exception as e:
            self.log.error(f"新增群组异常，原因是{e}")
            self.ckQz.base_get_img()
            assert False
